package com.witmore.neutron.ai.cognitive.config;

import com.witmore.neutron.ai.cognitive.service.CustomChatMemoryRepository;
import org.springframework.ai.chat.memory.ChatMemoryRepository;
import org.springframework.ai.chat.memory.repository.jdbc.JdbcChatMemoryRepository;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.transaction.PlatformTransactionManager;

/**
 * Description: ChatMemoryConfig
 * Author: 豆子高
 * Date: 2025/6/6 17:49
 */
@Configuration
public class ChatMemoryConfig {

    @Bean
    public ChatMemoryRepository chatMemoryRepository(JdbcTemplate jdbcTemplate,
                                                     PlatformTransactionManager platformTransactionManager) {
        // 1. 创建原始实现
        JdbcChatMemoryRepository originalRepository = JdbcChatMemoryRepository.builder()
                .jdbcTemplate(jdbcTemplate)
                .transactionManager(platformTransactionManager)
                .build();
        return new CustomChatMemoryRepository(originalRepository);
    }
}
